<%-- 
   - Author: Asna Khader
  - Date: 05-MAR-2012
  - Copyright Notice: TRAKHEES
  - Description: review/form.jsp
 --%>
 <%@ include file="/WEB-INF/view/include.jsp"%>

    <div class="t_tmiddle-right">
    	    <div id="tabs">
	      <ul id="TabHeader">
	        <li><a href="#ApplicationDetails"><spring:message code="header.app.details" /></a></li>
	      </ul>
	      <form:form modelAttribute="VisitVisaLicenseInfo" name="VisitVisaReviewFrm"  id="VisitVisaReviewFrm"  method="POST" class="t_form">
				<spring:hasBindErrors
							name="VisitVisaLicenseInfo">
								<script type="text/javascript">
									$(document).ready(
											function() {
												jAlert('error', '<li><form:errors path="*" delimiter="<li>"/>',
														'<spring:message code="label.errormessage" />');
											});
						</script>
			    </spring:hasBindErrors>
			     <table  style="width: 100%">
			    	<tr height="5px;"><td colspan="3"></td></tr>
			    	<tr><td width="20%"></td><td align="center"><div class="t_gin-grey-txt"><spring:message code="label.wfstatus" />${VisitVisaLicenseInfo.wfStatus}</div></td><td width="20%"></td></tr>
			    </table>
			    
				<%@include file="AppDetails.jsp" %>
	        	 
		 </form:form>
		 </div>
	      
       </div>
    <!--Middle Right Close-->
<script>
var submAction = null;

function setAction(inaction){
	submAction = inaction;
}
		$().ready(function() {
						

		
			$(".topnav").accordion({
				accordion:false,
				speed: 500,
				closedSign: '<img src=\'resources/images/common/close.jpg\' />',
				openedSign: '<img src=\'resources/images/common/open.jpg\' />'
			});
			
			
			
			$("#VisitVisaReviewFrm").validate({
				onfocusout:false,
				onkeyup:false,
				onclick: false,			
				rules : {
					//Employee Details
					adminComments : {
						required : {
							depends: function(element) {
					           return submAction == "reject";
					        }
						}
					},
					fnpServiceCode : {
						required : {
							depends: function(element) {
					           return submAction == "submit";
					        }
						}
					}
				},
				
				onfocusout:false,
				onkeyup:false,
				onclick: false,
				
				submitHandler: function (form) {
					blockPage();
					form.submit();
				},
				
				showErrors : function(errorMap, errorList) {
					
					var errors = '<ul>';
					var label;				
					if (errorList.length) {
						$.each(errorMap, function(name, value) {
							label = $("label[for='" + name + "']").html();
							label = value + '[' + label + ']';
							errors = errors + '<li>' + label + '</li>';
							

						});
						errors = errors + '</ul>';
						jAlert('error', errors, '<spring:message code="label.errormessage" />');
						return false;
					}
				}		
			});// end $("#EmploymentVisaFrm").validate
			$tabs = $("#tabs").tabs();	
			$('#TabHeader').removeClass('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all');
			$('#TabHeader > li').removeClass('ui-state-default ui-corner-top ui-state-active ui-state-hover');
			$('#tabs').removeClass('ui-widget ui-widget-content ui-corner-all');
			
			$('#tabs').tabs({
				select : function(event, ui) {
					
					var selected = $tabs.tabs('option', 'selected'); // => 0
					var clicked = ui.index; // => 0
										
					if( selected > clicked )
						return true;
					
					var isValid = validate();// form validation returning true or false
					
					return isValid;
				}
			});
			
	
			$('#AppDet-Next').click(function() { // bind click event to link			
				$tabs.tabs('select', 1);
				return false;
				//$('#EmploymentVisaFrm').submit();
			});
			
			$('#SubDet-Prev').click(function() { // bind click event to link			
				$tabs.tabs('select', 0);
				return false;
			});
		});	
		
		function validate() {
			var selected = $tabs.tabs('option', 'selected'); // => 0		
			
			if(selected == 1)
			{
			return ($("#VisitVisaReviewFrm").validate().element("#fnpServiceCode"));
			}
			else return true;
		}
		
		
		function submitForm(divId){
				$('#VisitVisaReviewFrm').append($("#"+divId).html());
				var input = $("<input>").attr("type", "hidden").attr("name", "MainUserApprove").val("MainUserApprove");
				$('#VisitVisaReviewFrm').append($(input));
				$.fancybox.showLoading();
				$('#VisitVisaReviewFrm').submit();
		}
		
		function cancelForm(divId){
			fancyConfirm('<spring:message code="message.cancel_confirmation_message" />'
					,'<spring:message code="button.No" />'
					,'<spring:message code="button.yes" />'
					, function(ret) {
						if(ret == true){
							//cancel
							var input = $("<input>").attr("type", "hidden").attr("name", "MainUserCancel").val("MainUserCancel");
							$('#VisitVisaReviewFrm').append($(input));
							$('#VisitVisaReviewFrm').submit();
							$.fancybox.showLoading();
						}
			});
		}
		
</script>